<?php
/* SVN FILE: $Id: lil.php 238 2010-03-06 11:35:39Z miha.nahtigal $ */
/**
 * Short description for lil.php
 *
 * Long description for lil.php
 *
 * PHP versions 4 and 5
 *
 * Copyright (c) 2009, Miha Nahtigal
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright (c) 2009, Miha Nahtigal
 * @link          http://www.nahtigal.com/
 * @package       lil
 * @subpackage    lil.views.helpers
 * @since         v 1.0
 * @version       $Revision: 238 $
 * @modifiedby    $LastChangedBy: miha.nahtigal $
 * @lastmodified  $Date: 2010-03-06 11:35:39 +0000 (Sat, 06 Mar 2010) $
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */
/**
 * LilHelper class
 *
 * @uses          Helper
 * @package       lil
 * @subpackage    lil.views.helpers
 */
class LilHelper extends AppHelper {
/**
 * helpers property
 *
 * @var array
 * @access public
 */
	var $helpers = array('Html', 'Text');
/**
 * __call method
 *
 * @param mixed $method
 * @param mixed $params
 * @access public
 * @return void
 */
	function __call($method, $params) {
		if (!empty($params[0]) && App::import('Model', $params[0])) {
			$model_name = $params[0];
			if (strpos($model_name, '.') !== false) {
				$model_name = substr($model_name, strpos($model_name, '.') + 1);
			}
			$model = new $model_name;
			
			if (is_callable(array($model, $method))) {
				unset($params[0]);
				return (call_user_func_array(array($model, $method), $params));
			}
		}
		return false;
	}
/**
 * permaLink method
 *
 * @param string $blog_name
 * @param mixed $post
 * @param array $options
 * @access public
 * @return void
 */
	function permalink($blog_name, $post, $options = array()) {
		$default_options = array(
			'caption' => $post['Post']['title']
		);
		$options = array_merge($default_options, (array)$options);
		
		return $this->Html->link($options['caption'], array(
			'admin'      => false,
			'plugin'     => 'lil',
			'controller' => 'posts',
			'action'     => 'view',
			'blog'       => $blog_name,
			'post'       => $post['Post']['slug']
		));
	}
/**
 * function exceprt
 * 
 * Extracts excerpt from text
 *
 * @param string $body
 * @param int $max_length
 * @param string $page_delimiter 
 * @return string
 * @access public
 * @static
 */
	function excerpt($body = null, $max_length=300, $page_delimiter='<!-- -- -->') {
		$ret = '';
		if (stripos($body, $page_delimiter)!==false) {
			$ret = substr($body, 0, stripos($body, $page_delimiter));
		} else {
			$ret = $this->Text->truncate($body, $max_length, '...', false, true);
		}
		return $ret;
	}
}
?>